| Conditions | 6 |
| Paths | 2 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** global: chrome */ |
||
| 44 | appsToDomTemplate: function(response) { |
||
| 45 | var |
||
| 46 | appName, confidence, version, |
||
| 47 | categories = [], |
||
|
|
|||
| 48 | template = []; |
||
| 49 | |||
| 50 | if ( response.tabCache && response.tabCache.count > 0 ) { |
||
| 51 | for ( appName in response.tabCache.appsDetected ) { |
||
| 52 | confidence = response.tabCache.appsDetected[appName].confidenceTotal; |
||
| 53 | version = response.tabCache.appsDetected[appName].version; |
||
| 54 | categories = []; |
||
| 55 | |||
| 56 | response.apps[appName].cats.forEach(function(cat) { |
||
| 57 | categories.push( |
||
| 58 | [ |
||
| 59 | 'a', { |
||
| 60 | target: '_blank', |
||
| 61 | href: 'https://wappalyzer.com/categories/' + popup.slugify(response.categories[cat].name) |
||
| 62 | }, [ |
||
| 63 | 'span', { |
||
| 64 | class: 'category' |
||
| 65 | }, [ |
||
| 66 | 'span', { |
||
| 67 | class: 'name' |
||
| 68 | }, |
||
| 69 | browser.i18n.getMessage('categoryName' + cat) |
||
| 70 | ] |
||
| 71 | ] |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | }); |
||
| 75 | |||
| 76 | template.push( |
||
| 77 | [ |
||
| 78 | 'div', { |
||
| 79 | class: 'detected-app' |
||
| 80 | }, [ |
||
| 81 | 'a', { |
||
| 82 | target: '_blank', |
||
| 83 | href: 'https://wappalyzer.com/applications/' + popup.slugify(appName) |
||
| 84 | }, [ |
||
| 85 | 'img', { |
||
| 86 | src: 'images/icons/' + ( response.apps[appName].icon || 'default.svg' ) |
||
| 87 | } |
||
| 88 | ], [ |
||
| 89 | 'span', { |
||
| 90 | class: 'label' |
||
| 91 | }, [ |
||
| 92 | 'span', { |
||
| 93 | class: 'name' |
||
| 94 | }, |
||
| 95 | appName |
||
| 96 | ], |
||
| 97 | ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) |
||
| 98 | ] |
||
| 99 | ], |
||
| 100 | categories |
||
| 101 | ] |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | } else { |
||
| 105 | template = [ |
||
| 106 | 'div', { |
||
| 107 | class: 'empty' |
||
| 108 | }, |
||
| 109 | browser.i18n.getMessage('noAppsDetected') |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | |||
| 113 | return template; |
||
| 114 | }, |
||
| 115 | |||
| 123 |